<!DOCTYPE html>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>

<p id="para">This<br> is a<a href="#g">test</a>of selection</p>

<script>
  test(() => {
    const lastText = document.getElementById('para').lastChild;
    assert_class_string(lastText, 'Text');

    const axPara = accessibilityController.accessibleElementById('para');
    const axLastText = axPara.childAtIndex(4);
    assert_equals(axLastText.role, 'AXRole: AXStaticText');
    assert_equals(axLastText.name, 'of selection');

    axLastText.setSelection(axLastText, 0, axLastText, 2);

    const selection = getSelection();
    assert_equals(selection.anchorNode, lastText, 'anchorNode');
    assert_equals(selection.anchorOffset, 0, 'anchorOffset');
    assert_equals(selection.focusNode, lastText, 'focusNode');
    assert_equals(selection.focusOffset, 2, 'focusOffset');
    assert_equals(selection.toString(), 'of', 'getSelection().toString()');
  }, 'Select text after a link.');
</script>
